import unittest
import json
from Finance_api.api.login import LoginAPI
from parameterized import parameterized
from Finance_api.utils import common_assert


def build_data():
    json_file = "./data/login.json"
    test_data = []
    with open(json_file, encoding="utf-8") as f:
        json_data = json.load(f)
        for case_data in json_data:
            login_data = case_data.get("login_data")
            status_code = case_data.get("status_code")
            status = case_data.get("status")
            description = case_data.get("description")
            test_data.append((login_data, status_code, status, description))
    return test_data


class TestLogin(unittest.TestCase):
    def setUp(self):
        self.login_api = LoginAPI()

    @parameterized.expand(build_data())
    def test_login(self, login_data, status_code, status, description):
        response = self.login_api.login(login_data=login_data)
        common_assert(self, response, status_code, status, description)
        print(response.json())
